package cn.wolfcode.trip.admin.controller;

import cn.wolfcode.trip.base.domain.Strategy;
import cn.wolfcode.trip.base.query.StrategyQueryObject;
import cn.wolfcode.trip.base.service.IStrategyService;
import cn.wolfcode.trip.base.service.ITravelService;
import cn.wolfcode.trip.base.utils.JSONResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/strategyTravel")
public class StrategyTravelController {
    @Autowired
    private IStrategyService strategyService;
    @Autowired
    private ITravelService travelService;
    //显示
    @RequestMapping("/list")
    public String list(@ModelAttribute("qo") StrategyQueryObject qo, Model model) {
        model.addAttribute("strategies", strategyService.listAll());
        model.addAttribute("pageInfo", strategyService.query(qo));
        model.addAttribute("travel", travelService.listAll());

        return "/strategyTravel/list";
    }
    //添加
    @RequestMapping("/insertRelation")
    @ResponseBody
    public Object insertRelation(Long strategyId, Long travelId) {
        JSONResult result = new JSONResult();
        try {
            strategyService.insertRelation(strategyId, travelId);
        } catch (Exception e) {
            e.printStackTrace();
            result.mark(e.getMessage());
        }
        return result;
    }
    //删除
    @RequestMapping("/deleteRelation")
    @ResponseBody
    public Object deleteRelation(Long strategyId, Long travelId) {
        JSONResult result = new JSONResult();
        try {
            strategyService.deleteRelation(strategyId, travelId);
        } catch (Exception e) {
            e.printStackTrace();
            result.mark(e.getMessage());
        }
        return result;
    }
}



